<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Wallet extends User_Controller
{


	function __construct()
	{
		parent::__construct();
      $this->smarty->assign("current_class", $this->router->fetch_class());
      $this->smarty->assign("current_method",$this->router->fetch_method());
      $this->uid = $this->user_data['id'];
      if( $this->logged_in==0) {header("Location:/");exit;}
	}

	public function index($value='')
	{
    //查询用户余额
    $this->load->model('User_model');
    $user_account = $this->User_model->get_user_account_by_id($this->user_data['id']);
    $this->smarty->assign("user_account", $user_account);

    //查询用户预期收入
    $expect_income = $this->User_model->get_expect_income_by_id($this->user_data['id']);
    $this->smarty->assign("expect_income", $expect_income);
    //查询用户佣金明细
    $commission_list  = $this->User_model->get_commission_by_user($this->user_data['id']);
    $this->smarty->assign("commission_list", $commission_list);
		//查询提现记录
		$this->load->model('User_withdrawal_model');
		$withdrawal = $this->User_withdrawal_model->get_withdrawl_by_user($this->user_data['id'],0,10);
		$this->smarty->assign("withdrawal_list", $withdrawal['result']);
		//查询提现中的金额
		$withdrawl_amount = $this->User_withdrawal_model->get_amount_for_withdrawl($this->user_data['id']);
		$this->smarty->assign("withdrawl_amount", $withdrawl_amount);

		$this->smarty->display("user/wallet.html");
	}

	function tixian(){
		$this->load->model('User_model');
    $user_account = $this->User_model->get_user_account_by_id($this->user_data['id']);
    $this->smarty->assign("user_account", $user_account);
		//查询提现中的金额
		$this->load->model('User_withdrawal_model');
		$withdrawl_amount = $this->User_withdrawal_model->get_amount_for_withdrawl($this->user_data['id']);
		$this->smarty->assign("withdrawl_amount", $withdrawl_amount);

		$post_data = $this->input->post();
		if($post_data){
			$tixian = array(
				'school_id' => $this->school_id,
				'user_id' => $this->user_data['id'],
				'amount' => $post_data['amount'],
				'balance' => $user_account['balance']-$post_data['amount'],
				'status' => 0,
				'add_time' => time(),
				'audit_time' => 0,
				'pay_time' => 0,
			 );
			 $this->db->insert('user_withdrawal',$tixian);
			 header("Location:/my/wallet/tixian_success");exit;
		}

		$this->smarty->display("user/wallet_tixian.html");
	}

	function tixian_success(){

		$this->smarty->display("user/wallet_tixian_scuess.html");
	}

}
